const router = require('koa-router')()
const { query } = require("../db")
const { URL } = require("url");
const path = require("path");
const fs = require("fs");
router.prefix('/comment');

//发起评论
router.post('/', async (ctx, next) => {
    let id = ctx.request.query.id;
    let content = ctx.request.body.content;
    let name = ctx.request.body.name;
    let url = ctx.request.body.url;
    let sql = "insert into comments (id, content, name, url) values('" + id + "', '" + content + "', '" + name + "', '" + url + "')";
    await query(sql, []);
    ctx.res.end(JSON.stringify({ "status": "ok" }))
})

//获取对应页评论
router.get("/", async (ctx, next) => {
    let sql = "select * from comments where id='" + ctx.request.query.id + "'";
    let results = await query(sql, []);
    ctx.res.end(JSON.stringify(results));
})

module.exports = router
